﻿using System.Text;
using Sanelib.Common.SystemSettings;

namespace Sanelib.CodeMaker.Generators
{
    public class ControllerGenerator
    {
        public static void Generate(DatabaseTableSchema tbSchema)
        {
            var sb = new StringBuilder();
            sb.AppendLine("using System.Web.Mvc;");
            sb.AppendLine("using AutoMapper;");
            sb.AppendLine("using WebApp.Services;");
            sb.AppendLine("");
            sb.AppendLine("namespace WebApp.Controllers");
            sb.AppendLine("{");
            sb.AppendLine("\tpublic class " + tbSchema.TableName + "Controller : SmartController");
            sb.AppendLine("\t{");
            sb.AppendLine("\t\tpublic " + tbSchema.TableName + " Controller(IUserSession userSession, IMappingEngine mappingEngine) : base(userSession, mappingEngine)");
            sb.AppendLine("\t\t{");
            sb.AppendLine("\t\t}");
            sb.AppendLine("");
            sb.AppendLine("\t\t[Authorize]");
            sb.AppendLine("\t\tpublic ActionResult Index()");
            sb.AppendLine("\t\t{");
            sb.AppendLine("\t\t\treturn View();");
            sb.AppendLine("\t\t}");
            sb.AppendLine("\t}");
            sb.AppendLine("}");

            System.IO.File.WriteAllText(Globals.CreateOrGetCustomPath("\\Controllers\\") + tbSchema.TableName + "Controller_Generated.cs", sb.ToString());
        }
    }
}
